﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace AUV5.Web.Pages
{
    public partial class Main : PageMasterBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
            if (base.PageBase.IsVerified)
            {
                //显示未读消息数
                int count = BLL.MessageBLL.Instance.GetUnReadMessage(base.PageBase.VerifiedUserID).Count;
                //+公告
                count += BLL.BulletinBLL.Instance.GetUnReadBulletin(base.PageBase.VerifiedUserID).Count;
                if (count == 0)
                {
                    lbMesCount.Text = "";
                    lbMesCount.Visible = false;
                }
                else
                {
                    lbMesCount.Visible = true;
                    lbMesCount.Text = count.ToString();
                    base.PageBase.NoticeInfo = string.Format("您有{0}条未读消息 <a class='bluetxt' href={1}>打开我的消息</a>", count, "/Pages/MessageBox.aspx");
                }

                //用户未激活提醒
                if (base.PageBase.VerifiedInfo.User.State == (int)Common.Enum.auvState.Disable)
                {
                    base.PageBase.NoticeInfo = string.Format("用户尚未激活，激活链接已发送到您的邮箱<a class='bluetxt' href='{0}'>点此重新发送</a>", "UserSendActiveEmail.aspx");
                }
                //pMasterNotice.Visible = true; 
                //订单统计
                lbUnfinishedOrderCount.Text = "8";

                //显示管理按钮
                if (BLL.RoleInfoBLL.Instance.GetRoleName(base.PageBase.VerifiedInfo.User.RoleID) == Common.PageBase.MANAGER)
                {
                    backEnd.Visible = true;
                }
                //base.PageBase.ErrorInfo = "test errorinfo";
                //base.PageBase.NoticeInfo = "test notiiceinfo";
                //base.PageBase.SuccessInfo = "test successinfo";

                ShowPageAlert();
            }
        }

        private void ShowPageAlert()
        {
            string script = "";

            string errorinfo = base.PageBase.ErrorInfo;
            if (!string.IsNullOrEmpty(errorinfo))
            {
                script += "showError(\"" + errorinfo + "\");";
                //base.PageBase.AlertGo("", "", "showError('" + errorinfo + "')");
                base.PageBase.ErrorInfo = "";
            }


            string noticeinfo = base.PageBase.NoticeInfo;
            if (!string.IsNullOrEmpty(noticeinfo))
            {
                script += "showNotice(\"" + noticeinfo + "\");";
                //base.PageBase.AlertGo("", "", "showNotice('" + noticeinfo + "')");
                base.PageBase.NoticeInfo = "";
            }


            string successinfo = base.PageBase.SuccessInfo;
            if (!string.IsNullOrEmpty(successinfo))
            {
                script += "showSuccess(\"" + successinfo + "\");";
                //base.PageBase.AlertGo("", "", "showSuccess('" + successinfo + "')"); 
                base.PageBase.SuccessInfo = "";
            }


            base.PageBase.AlertGo("", "", script);
        }
    }
}